package com.shixi.shixitraining.shixitraining.ui.tabhome.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.shixi.shixitraining.shixitraining.R;
import com.shixi.shixitraining.shixitraining.base.BaseActivity;
import com.shixi.shixitraining.shixitraining.http.CallbackImple;
import com.shixi.shixitraining.shixitraining.http.HttpUtil;
import com.shixi.shixitraining.shixitraining.ui.tabhome.adapter.HomeOverseasAdapter;
import com.shixi.shixitraining.shixitraining.ui.tabhome.entity.HotJobBean;
import com.shixi.shixitraining.shixitraining.util.TitleUtil;
import com.shixi.shixitraining.shixitraining.util.ToastUtil;
import com.shixi.shixitraining.shixitraining.view.recycleview.RecycleItemClickListener;

import java.util.List;

import retrofit2.Call;

import static com.shixi.shixitraining.shixitraining.constant.Constants.JOBS;

public class HomeGrideOverseasActivity extends BaseActivity implements View.OnClickListener {

    private ImageView mBackImg;
    private View homeTitleBarBgView;
    private int distanceY = 0;
    private int DISTANCE_WHEN_TO_SELECTED = 40;
    private Context activity;
    private TextView mAuthenTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_gride_overseas);
        initTitle();
        initData();
    }
//基本数据请求
    private void initData() {

        HttpUtil.getInstance().getApiInterface().hotJob(JOBS).enqueue(new CallbackImple<HotJobBean>() {
            @Override
            public void onError(Call<HotJobBean> call, Throwable t) {
                ToastUtil.showShortToast(HomeGrideOverseasActivity.this,t.getMessage());
            }
            @Override
            public void onSuccess(Call<HotJobBean> call, HotJobBean response) {
                if (response!=null){

                    if (response.getData()!=null){
                        final List<HotJobBean.DataBean.ListsBean>    listData = response.getData().getLists();
                        List<HotJobBean.DataBean.NatureBean> nature = response.getData().getNature();
                        List<HotJobBean.DataBean.SettrBean> settr = response.getData().getSettr();
                        List<HotJobBean.DataBean.TypeBean> type = response.getData().getType();
                        List<HotJobBean.DataBean.DurationBean> duration = response.getData().getDuration();

                        RecyclerView mRcView = (RecyclerView) findViewById(R.id.home_overseas_rcview);
                        LinearLayoutManager manager = new LinearLayoutManager(HomeGrideOverseasActivity.this);
                        manager.setOrientation(LinearLayoutManager.VERTICAL);
                        mRcView.setLayoutManager(manager);
                        HomeOverseasAdapter adapter = new HomeOverseasAdapter(HomeGrideOverseasActivity.this,listData);
                        mRcView.setAdapter(adapter);


                        mRcView.addOnItemTouchListener(new RecycleItemClickListener(HomeGrideOverseasActivity.this) {
                            @Override
                            public void itemClickListener(View view, int position) {
                                HotJobBean.DataBean.ListsBean listsBean = listData.get(position);
                                String jobId = listsBean.getId();
                                Intent intent=new Intent(HomeGrideOverseasActivity.this,
                                        OverseasDetailActivity.class);
                                Bundle bundle =new Bundle();
                                bundle.putString("jobId",jobId);
                                intent.putExtras(bundle);
                                startActivity(intent);
                            }
                        });
                    }else {
                        ToastUtil.showShortToast(HomeGrideOverseasActivity.this,response.getMsg());
                    }

                }else {
                    ToastUtil.showShortToast(HomeGrideOverseasActivity.this,response.getMsg());
                }

            }
        });

    }


    private void initTitle() {
            TitleUtil titleUtil = new TitleUtil(findViewById(R.id.top_bar_layout));
            titleUtil.initTitle(4, R.id.top_bar_center_tv, R.id.top_bar_left_img, 0, R.drawable.icon_back,
                    0, "海外就业", "", "");
            ImageView mBackImg = (ImageView) findViewById(R.id.top_bar_left_img);
            mBackImg.setOnClickListener(this);

        }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.top_bar_left_img:
                this.finish();
                break;
        }
    }
}
